
import java.io.IOException;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andik Taufiq
 * Components for main menu
 * March, 27 2010 - Bandung, Indonesia
 */
public class Menu {
    private int type;
    private String label;
    private String description;
    public int x, y, height, width, index, matchIndex;

    public Image highlight;
    public Image icon1;
    public Image icon2;
    public Image icon3;
    public Image icon4;
    public Image icon5;
    
    public Menu(int x, int y, int type, int index, int matchIndex,
            String label, String description) {
        this.x = x;
        this.y = y;
        this.type = type;
        this.index = index;
        this.matchIndex = matchIndex;
        this.label = label;
        this.description = description;

        try {
            highlight	= Image.createImage("/highlight.png");
            icon1		= Image.createImage("/new.png");
            icon2		= Image.createImage("/settings.png");
            icon3		= Image.createImage("/instruction.png");
            icon4		= Image.createImage("/about.png");
            icon5		= Image.createImage("/exit.png");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        this.height = icon1.getHeight() + 15;
        this.width = highlight.getWidth();        
    }

    public void paint(Graphics g) {
        if (index == matchIndex) {
            g.drawImage(highlight, x, y, Graphics.TOP | Graphics.LEFT);
            g.setColor(0xFFF005);
            g.setFont(MainCanvas.boldFont);
            g.drawString(label, x + icon1.getWidth() + 10, y + 5, Graphics.TOP | Graphics.LEFT);
            g.setColor(0xDDDDDD);
            g.setFont(MainCanvas.plainFont);
            g.drawString(description, x + icon1.getWidth() + 10, y + 5 + MainCanvas.plainFont.getHeight(), Graphics.TOP | Graphics.LEFT);
        } else {
            g.setColor(0x8EBCE8);
            g.setFont(MainCanvas.boldFont);
            g.drawString(label, x + icon1.getWidth() + 10, y + 5, Graphics.TOP | Graphics.LEFT);
            g.setColor(0x4A77A2);
            g.setFont(MainCanvas.plainFont);
            g.drawString(description, x + icon1.getWidth() + 10, y + 5 + MainCanvas.plainFont.getHeight(), Graphics.TOP | Graphics.LEFT);
        }
        switch (type) {
            case 1:
                g.drawImage(icon1, x + 5, y + 5, Graphics.TOP | Graphics.LEFT);
            break;
            case 2:
                g.drawImage(icon2, x + 5, y + 5, Graphics.TOP | Graphics.LEFT);
            break;
            case 3:
                g.drawImage(icon3, x + 5, y + 5, Graphics.TOP | Graphics.LEFT);
            break;
            case 4:
                g.drawImage(icon4, x + 5, y + 5, Graphics.TOP | Graphics.LEFT);
            break;
            case 5:
                g.drawImage(icon5, x + 5, y + 5, Graphics.TOP | Graphics.LEFT);
            break;
        }

    }
}
